#include <stdio.h>
#define N sizeof(_departure) / sizeof(_departure[0])
int main(void)
{
    const int _departure[][2] = {
        {8, 0},
        {9, 43},
        {11, 19},
        {12, 47},
        {14, 0},
        {15, 45},
        {19, 0},
        {21, 45}
    };
    int departure[N];
    for (int i = 0; i < N; i++) {
        departure[i] = _departure[i][0] * 60 + _departure[i][1];
        //printf("%d\n", departure[i]);
    }

    const int _arriving[][2] = {
        {10, 16},
        {11, 52},
        {13, 31},
        {15, 0},
        {16, 8},
        {17, 33},
        {21, 20},
        {23, 58}
    };
    int arriving[N];
    for (int i = 0; i < N; i++) {
        arriving[i] = _arriving[i][0] * 60 + _arriving[i][1];
    }

    int hh, mm;
    printf("Enter a 24-hour time: ");
    scanf("%d:%d", &hh, &mm);
    int stamp = hh * 60 + mm;
    int last = -1;
    for (int i = 0; i < N; i++) {
        if (stamp < departure[i])
            break;
        last = i;
    }
    if (last == -1)
        last = N - 1;
    printf("Closet departure time is %d:%02d %c.m., arriving at %d:%02d %c.m.\n", 
        (_departure[last][0] == 12) ? 12 : _departure[last][0] % 12, _departure[last][1], (_departure[last][0] < 12) ? 'a' : 'p',
        (_arriving[last][0] == 12) ? 12 : _arriving[last][0] % 12, _arriving[last][1], (_arriving[last][0] < 12) ? 'a' : 'p');

    return 0;
}